import { generateRandomValue } from "./handler";

/**
 * 设备状态统计数据生成方法
 * @returns [Array<Object>] 返回工单数据
 */
export const generateEquipmentStateData = () => {
  const data = [];
  const typeList = ["正常设备", "离线设备", "故障设备"];
  let total = 0;
  typeList.forEach(item => {
    const value = generateRandomValue(3, 0, 999);
    data.push({ name: item, value });
    total += value;
  });

  data.forEach(item => {
    item.rate = ((item.value / total) * 100).toFixed(2);
  });

  return data;
};

/**
 * 设备数据生成方法
 * @returns [Array<Object>] 返回工单数据
 */
export const generateEquipmentData = () => {
  const data = [];
  const typeList = [
    {
      name: "监控",
      icon: "/static/img/park/item/monitor.png",
      bgImg: "/static/img/park/item/monitor-bg.png"
    },
    {
      name: "空调",
      icon: "/static/img/park/item/air-conditioning.png",
      bgImg: "/static/img/park/item/air-conditioning-bg.png"
    },
    {
      name: "门禁",
      icon: "/static/img/park/item/access-control.png",
      bgImg: "/static/img/park/item/access-control-bg.png"
    },
    {
      name: "消防",
      icon: "/static/img/park/item/fire-protection.png",
      bgImg: "/static/img/park/item/fire-protection-bg.png"
    },
    {
      name: "电梯",
      icon: "/static/img/park/item/elevator.png",
      bgImg: "/static/img/park/item/elevator-bg.png"
    }
  ];

  typeList.forEach((item, index) => {
    const total = generateRandomValue(3);
    const abnormal = generateRandomValue(1);
    const normal = total - abnormal;
    data.push({
      id: index + 1,
      name: item.name,
      icon: item.icon,
      bgImg: item.bgImg,
      total,
      normal,
      abnormal
    });
  });

  return data;
};

/**
 * 巡检维保数据生成方法
 * @returns [Array<Object>] 返回工单数据
 */
export const generateMaintenanceData = () => {
  return [
    {
      name: "监控",
      value: 60,
      rate: 60,
      max: 100
    },
    {
      name: "消防设备",
      value: 88,
      rate: 88,
      max: 100
    },
    {
      name: "电梯",
      value: 20,
      rate: 20,
      max: 100
    },
    {
      name: "门禁",
      value: 90,
      rate: 90,
      max: 100
    },
    {
      name: "空调",
      value: 100,
      rate: 100,
      max: 100
    }
  ];
};

/**
 * 设备告警统计数据生成方法
 * @returns [Array<Object>] 返回工单数据
 */
export const generateAlarmStatisticsListData = () => {
  return [
    {
      name: "正常",
      value: 229,
      rate: 46.2
    },
    {
      name: "异常",
      value: 143,
      rate: 28.8
    },
    {
      name: "故障",
      value: 123,
      rate: 25
    }
  ];
};

/**
 * 设备预警数据生成方法
 * @returns [Array<Object>] 返回工单数据
 */
export const generateEquipmentWarnData = () => {
  return [
    {
      id: 1,
      name: "烟感-5030523",
      position: "会展中心A座A区1001",
      state: 1
    },
    {
      id: 2,
      name: "门禁-1788",
      position: "会展中心A座A区1001",
      state: 0
    },
    {
      id: 3,
      name: "烟感-5030523",
      position: "会展中心A座A区1001",
      state: 1
    },
    {
      id: 4,
      name: "门禁-1788",
      position: "会展中心A座A区1001",
      state: 0
    },
    {
      id: 5,
      name: "烟感-5030523",
      position: "会展中心A座A区1001",
      state: 0
    },
    {
      id: 6,
      name: "门禁-1993",
      position: "会展中心A座A区1001",
      state: 1
    },
    {
      id: 7,
      name: "烟感-5030548",
      position: "会展中心A座A区1001",
      state: 0
    },
    {
      id: 8,
      name: "烟感-5032048",
      position: "会展中心A座A区1001",
      state: 0
    }
  ];
};

/**
 * 检修记录数据生成方法
 * @returns [Array<Object>] 返回工单数据
 * @description state ['正常', '故障']
 */
export const generateMaintenanceRecordsData = () => {
  return [
    {
      id: 1,
      name: "烟感-5030524",
      position: "会展中心A座A区1001",
      state: 1,
      user: "凤欣源",
      date: "2023-11-28 12:00"
    },
    {
      id: 2,
      name: "门禁-1781",
      position: "会展中心A座A区1001",
      state: 1,
      user: "曹添池",
      date: "2023-11-28 11:57"
    },
    {
      id: 3,
      name: "烟感-5030521",
      position: "会展中心A座A区1001",
      state: 1,
      user: "孔瑞堂",
      date: "2023-11-28 11:49"
    },
    {
      id: 4,
      name: "门禁-1726",
      position: "会展中心A座A区1001",
      state: 1,
      user: "袁欣汝",
      date: "2023-11-28 11:09"
    },
    {
      id: 5,
      name: "烟感-5030590",
      position: "会展中心A座A区1001",
      state: 1,
      user: "任国栋",
      date: "2023-11-28 10:29"
    },
    {
      id: 6,
      name: "门禁-1998",
      position: "会展中心A座A区1001",
      state: 1,
      user: "杨佳毅",
      date: "2023-11-28 10:02"
    },
    {
      id: 7,
      name: "烟感-5030231",
      position: "会展中心A座A区1001",
      state: 1,
      user: "陶佳欣",
      date: "2023-11-28 09:59"
    },
    {
      id: 8,
      name: "烟感-5032022",
      position: "会展中心A座A区1001",
      state: 1,
      user: "昌晨涵",
      date: "2023-11-27 15:50"
    }
  ];
};
